import pandas as pd
import numpy as np
import numba

def rolling_regression_b1(x):
    x1=x[:,0] #注意这个0对应的是'HS300_return'列系数
    y1=x[:,1] #注意这个1对应的是'指数y_return'列系数
    beta1 = np.nansum(y1*(x1-np.nanmean(x1)))/(np.nansum((x1-np.nanmean(x1))*(x1-np.nanmean(x1)))+0.00000001)
    # beta1=(y1*(x1-x1.mean(skipna=True))).sum(skipna=True)/((x1-x1.mean(skipna=True))*(x1-x1.mean(skipna=True))).sum(skipna=True) #从线性回归公式的角度计算beta1
    return beta1
    # t=df.rolling(50,method="table").apply(rolling_regression,raw=True, engine="numba")

def rolling_regression_b0(x):
    x1=x[:,0] #注意这个0对应的是'HS300_return'列系数
    y1=x[:,1] #注意这个1对应的是'指数y_return'列系数
    beta1 = np.nansum(y1*(x1-np.nanmean(x1)))/(np.nansum((x1-np.nanmean(x1))*(x1-np.nanmean(x1)))+0.00000001)
    beta0 = np.nanmean(y1) - beta1*np.nanmean(x1)
    return beta0

def ma_short_to_long(df, s, l):
    ma_short = df.rolling(s, min_periods=1).mean() 
    ma_long = df.rolling(l, min_periods=1).mean() 
    return ma_short/ma_long

def cur_to_pre(df, n):
    return df/df.shift(n)

def cur_to_pre_log(df,n):
    return np.log(cur_to_pre(df,n))

def ma_cur_to_pre(df, c, p, n):
    ma_cur = df.rolling(c, min_periods=1).mean()
    ma_pre = df.rolling(p, min_periods=1).mean()
    return ma_cur/ma_pre.shift(n)

def ser_rank(df, n):
    return df.rolling(n, min_periods=1).rank()

def ser_Corr(x,y,n):
    #window日滚动相关系数
    return x.rolling(n, min_periods=1).corr(y)

class Alphas_value:
    def __init__(self, stock_df):
        stock_df = stock_df.fillna(method='ffill')
        self.pe = stock_df['pe'] 
        self.pettm = stock_df['pe_ttm'] 
        self.pb = stock_df['pb']  
        self.ps = stock_df['ps']
        self.psttm = stock_df['ps_ttm']
        self.dv_ratio = stock_df['dv_ratio']
        self.dv_ttm = stock_df['dv_ttm']
        self.volume = stock_df['volume']
        self.total_mv = stock_df['total_mv']#总市值
        self.volume = stock_df['volume']
        self.lagret = stock_df['close']/stock_df['close'].shift(1)
        self.ampli = (stock_df['high']-stock_df['low'])/stock_df['close'].shift(1)

    # 0 param
    def alpha_v1(self):
        return self.total_mv

    def alpha_v2(self):
        return self.pettm - self.pe

    def alpha_v3(self):
        return self.psttm - self.ps

    def alpha_v4(self):
        return self.dv_ttm - self.dv_ratio
        
    # 1 param
    def alpha_v5(self, N): 
        return cur_to_pre(self.pettm, N)

    def alpha_v6(self, N):
        return cur_to_pre(self.pb, N)

    def alpha_v7(self, N):
        return cur_to_pre(self.psttm, N)

    def alpha_v8(self, N):
        return cur_to_pre(self.dv_ttm, N)

    def alpha_v9(self, N):
        return cur_to_pre(self.total_mv, N)

    def alpha_v10(self, n):
        return ser_Corr(self.pettm, self.lagret, n)

    def alpha_v11(self, n):
        return ser_Corr(self.psttm, self.lagret, n)

    def alpha_v12(self, n):
        return ser_Corr(self.dv_ttm, self.lagret, n)

    # 2 param
    def alpha_v13(self, s, l): 
        return ma_short_to_long(self.ampli, s, l)

    def alpha_v14(self, s, l): 
        return ma_short_to_long(self.pettm, s, l)

    def alpha_v15(self, s, l):
        return ma_short_to_long(self.pb, s, l)

    def alpha_v16(self, s, l):
        return ma_short_to_long(self.psttm, s, l)

    def alpha_v17(self, s, l):
        return ma_short_to_long(self.dv_ttm, s, l)

    def alpha_v18(self, s, l):
        return ma_short_to_long(self.total_mv, s, l)

    # 3 param
    def alpha_v19(self, c, p, n): 
        return ma_cur_to_pre(self.pettm, c, p, n)

    def alpha_v20(self, c, p, n):
        return ma_cur_to_pre(self.pb, c, p, n)

    def alpha_v21(self, c, p, n):
        return ma_cur_to_pre(self.psttm, c, p, n)

    def alpha_v22(self, c, p, n):
        return ma_cur_to_pre(self.dv_ttm, c, p, n)

    def alpha_v23(self, c, p, n):
        return ma_cur_to_pre(self.total_mv, c, p, n)

    def alpha_v24(self, c, p, n): 
        return ma_cur_to_pre(self.pettm-self.pe, c, p, n)

    def alpha_v25(self, c, p, n):
        return ma_cur_to_pre(self.psttm-self.ps, c, p, n)

    def alpha_v26(self, c, p, n):
        return ma_cur_to_pre(self.dv_ttm-self.dv_ratio, c, p, n)

    def alpha_v27(self, c, p, n):
        return ma_cur_to_pre(self.ampli, c, p, n)


class Alpha_other():
    bound_ratio = pd.read_pickle(r'data\stock_data\daily\other\bound_ratio.pkl.gzip')
    bound_ratio = bound_ratio.fillna(method='ffill')
    currency_boc_safe = pd.read_pickle(r'data\stock_data\daily\other\currency_boc_safe.pkl.gzip')
    currency_boc_safe = currency_boc_safe.fillna(method='ffill')
    rate_interbank = pd.read_pickle(r'data\stock_data\daily\other\rate_interbank.pkl.gzip')
    pepb_sz = pd.read_pickle(r'data\stock_data\daily\other\pepb_sz.pkl.gzip')
    pepb_sh = pd.read_pickle(r'data\stock_data\daily\other\pepb_sh.pkl.gzip')
    pepb_kc = pd.read_pickle(r'data\stock_data\daily\other\pepb_kc.pkl.gzip')
    pepb_cy = pd.read_pickle(r'data\stock_data\daily\other\pepb_cy.pkl.gzip')
    pepb_50 = pd.read_pickle(r'data\stock_data\daily\other\pepb_000016.pkl.gzip')
    pepb_300 = pd.read_pickle(r'data\stock_data\daily\other\pepb_000300.pkl.gzip')
    pepb_1000 = pd.read_pickle(r'data\stock_data\daily\other\pepb_000852.pkl.gzip')
    pepb_500 = pd.read_pickle(r'data\stock_data\daily\other\pepb_000905.pkl.gzip')
    ebs_lg = pd.read_pickle(r'data\stock_data\daily\other\ebs_lg.pkl.gzip')
    ebs_lg = ebs_lg.fillna(method='ffill')

    def __init__(self, stock_df):
        stock_df = stock_df.fillna(method='ffill')
        self.pe = stock_df['pe'] 
        self.pettm = stock_df['pe_ttm'] 
        self.pb = stock_df['pb']  
        self.ps = stock_df['ps']
        self.psttm = stock_df['ps_ttm']
        self.dv_ratio = stock_df['dv_ratio']
        self.dv_ttm = stock_df['dv_ttm']
        self.volume = stock_df['volume']
        self.total_mv = stock_df['total_mv']#总市值
        self.volume = stock_df['volume']
        self.lagret = stock_df['close']/stock_df['close'].shift(1)
        self.ampli = (stock_df['high']-stock_df['low'])/stock_df['close'].shift(1) 
        self.get_other_data()

    def get_other_data(self):
        self.bound_ratio = Alpha_other.bound_ratio
        self.currency_boc_safe = Alpha_other.currency_boc_safe
        self.rate_interbank = Alpha_other.rate_interbank
        self.pepb_sz = Alpha_other.pepb_sz
        self.pepb_sh = Alpha_other.pepb_sh
        self.pepb_kc = Alpha_other.pepb_kc
        self.pepb_cy = Alpha_other.pepb_cy
        self.pepb_50 = Alpha_other.pepb_50
        self.pepb_300 = Alpha_other.pepb_300
        self.pepb_1000 = Alpha_other.pepb_1000
        self.pepb_500 = Alpha_other.pepb_500
        self.ebs_lg = Alpha_other.ebs_lg  

    # param 0 
    def alpha_o1(self):
        return self.bound_ratio['中国国债收益率2年']/self.dv_ttm

    def alpha_o1(self):
        return self.bound_ratio['美国国债收益率10年']/self.dv_ttm

    def alpha_o2(self):
        return self.bound_ratio['中国国债收益率10年']/self.dv_ttm

    def alpha_o3(self):
        return self.bound_ratio['中国国债收益率30年']/self.dv_ttm

    def alpha_o4(self):
        return self.bound_ratio['中国国债收益率10年-2年']/self.dv_ttm

    def alpha_o5(self):
        return self.ebs_lg['股债利差']

     # param 1
    def alpha_o6(self, n):
        df = pd.concat([self.pepb_sh['addTtmPe']-self.pettm, self.lagret],axis=1)  
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o7(self, n):
        df = pd.concat([self.pepb_sh['addTtmPe']-self.pettm, self.lagret],axis=1)  
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o8(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o9(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o10(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o11(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o12(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh
    
    def alpha_o13(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh
    
    def alpha_o14(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o15(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        return stock/sh

    def alpha_o16(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o17(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o18(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o19(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o20(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]
    
    def alpha_o21(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]
    
    def alpha_o22(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o23(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]


    def alpha_o24(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o25(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o26(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o27(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o28(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]
    
    def alpha_o29(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]
    
    def alpha_o30(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o31(self, n):
        stock = self.lagret.rolling(n, min_periods=1).sum()
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        sh = sh_lagret.rolling(n, min_periods=1).sum()
        df = pd.concat([sh ,stock],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o32(self, n):
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o33(self, n):
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o34(self, n):
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o35(self, n):
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o36(self, n):
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o37(self, n):
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o38(self, n):
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        return cur_to_pre(sh_lagret, n)
    
    def alpha_o39(self, n):
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        return cur_to_pre(sh_lagret, n)

    def alpha_o40(self, n):
        return ser_Corr(self.ebs_lg['股债利差'], self.dv_ttm, n)

    def alpha_o41(self, n):
        df = pd.concat([self.ebs_lg['股债利差']/self.dv_ttm, self.lagret],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b0,raw=True, engine="numba")
        return t.iloc[:,0]

    def alpha_o42(self, n):
        df = pd.concat([self.ebs_lg['股债利差']/self.dv_ttm, self.lagret],axis=1)
        t = df.rolling(n, method="table", min_periods=1).apply(rolling_regression_b1,raw=True, engine="numba")
        return t.iloc[:,0]

    # param 2       
    def alpha_o43(self,s,l):
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l) 
  
    def alpha_o44(self,s,l):
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l)

    def alpha_o45(self,s,l):
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l)
      
    def alpha_o45(self,s,l):
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l)
        
    def alpha_o46(self,s,l):
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l) 
        
    def alpha_o47(self,s,l):
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l) 
        
    def alpha_o48(self,s,l):
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l) 

     
    def alpha_o49(self,s,l):
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        return ma_short_to_long(sh_lagret, s,l)

    def alpha_o50(self,s,l):
        return ma_short_to_long(self.ebs_lg['股债利差'], s,l)

    # param 3
    def alpha_o51(self, c, p, n):
        return ma_cur_to_pre(self.pepb_sh['addTtmPe']-self.pettm, c, p, n)

    def alpha_o52(self, c, p, n):
        return ma_cur_to_pre(self.pepb_sh['addPb']-self.pb, c, p, n)

    def alpha_o53(self, c, p, n):
        return ma_cur_to_pre(self.pepb_sh['averageTtmPe']-self.pettm, c, p, n)

    def alpha_o54(self, c, p, n):
        return ma_cur_to_pre(self.pepb_sh['averagePb']-self.pb, c, p, n)

    def alpha_o55(self,c, p, n):
        return ma_cur_to_pre(self.ebs_lg['股债利差'], c, p, n) 

    def alpha_o56(self,c, p, n):
        sh_lagret = self.pepb_sz['close']/self.pepb_sz['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o57(self,c, p, n):
        sh_lagret = self.pepb_cy['close']/self.pepb_cy['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o58(self,c, p, n):
        sh_lagret = self.pepb_1000['close']/self.pepb_1000['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o59(self,c, p, n):
        sh_lagret = self.pepb_300['close']/self.pepb_300['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o60(self,c, p, n):
        sh_lagret = self.pepb_500['close']/self.pepb_500['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o61(self, c, p, n):
        sh_lagret = self.pepb_50['close']/self.pepb_50['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n)

    def alpha_o62(self,c, p, n):
        sh_lagret = self.pepb_kc['close']/self.pepb_kc['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 

    def alpha_o63(self,c, p, n):
        sh_lagret = self.pepb_sh['close']/self.pepb_sh['close'].shift(1)
        return ma_cur_to_pre(sh_lagret, c, p, n) 
        

# price = pd.read_pickle(r'F:\blackwing_new\stock\stock\comdty_v1_laptop\demo_1207\data\stock_data\daily\price\000001.pkl.gzip')
# value = pd.read_pickle(r'F:\blackwing_new\stock\stock\comdty_v1_laptop\demo_1207\data\stock_data\daily\market_value\000001.pkl.gzip')
# data = pd.concat([price,value], axis=1)
# data = data.astype(np.float32)
# ao = Alpha_other(data)
# t = ao.alpha_o6(5)
# print('fin')       



# def foo(a = 1, *kargs):
#     print(a, kargs)

# foo(1, 6,3)
# print('fin')
    
        






    

